#!/usr/bin/env python
# coding=utf-8
# __author__ = 'Yunchao Ling'

# import sys
#
# ht = {}
# infile = open(sys.argv[1], "r")
# infile.readline()
# for line in infile:
#     line = line.rstrip()
#     path = line.split("\t")[0]
#     if not ht.has_key(path):
#         ht[path] = 1
#     else:
#         ht[path] = ht[path] + 1
# infile.close()
# for key in ht.keys():
#     if ht[key] >= 2:
#         print key + "\t" + str(ht[key])
# print len(ht)

def Get3754():
    from pymongo import MongoClient

    outfile = open("3754.txt", "w")

    DB_NAME = "pmc"
    COLLECTION_NAME = "filelist"

    connection = MongoClient('localhost', 27017)
    db = connection[DB_NAME]
    collection = db[COLLECTION_NAME]

    results = collection.find({"nofile": {"$exists": 0}, "type": "pdf"})
    for result in results:
        path = result["path"]
        outfile.write(path + "\n")
        outfile.flush()
    connection.close()
    outfile.close()


def Get3751():
    ht = {}
    infile0101 = open("file_list.pdf.txt.20160101", "r")
    infile0107 = open("file_list.pdf.txt.20160107", "r")
    outfile = open("3751.txt", "w")
    infile0101.readline()
    infile0107.readline()
    for line in infile0101:
        line = line.rstrip()
        path = line.split("\t")[0]
        ht[path] = 0
    infile0101.close()
    for line in infile0107:
        line = line.rstrip()
        path = line.split("\t")[0]
        if not ht.has_key(path):
            outfile.write(path + "\n")
            outfile.flush()
    infile0107.close()
    outfile.close()


def Compare_3751_3754():
    ht = {}

    infile3751 = open("3751.txt", "r")
    infile3754 = open("3754.txt", "r")

    for line in infile3751:
        line = line.rstrip()
        ht[line] = 0
    infile3751.close()
    for line in infile3754:
        line = line.rstrip()
        if not ht.has_key(line):
            print line
    infile3754.close()


def GetLines(filepath):
    infile = open(filepath, "r")
    infile.readline()
    count = 0
    for line in infile:
        count += 1
    infile.close()
    print count


def Find3():
    ht = {}
    infile0101 = open("file_list.pdf.txt.20160101", "r")
    infile0107 = open("file_list.pdf.txt.20160107", "r")
    infile0101.readline()
    infile0107.readline()
    for line in infile0101:
        line = line.rstrip()
        path = line.split("\t")[0]
        ht[path] = 0
    infile0101.close()
    for line in infile0107:
        line = line.rstrip()
        path = line.split("\t")[0]
        if ht.has_key(path):
            ht.pop(path)
    infile0107.close()
    for key in ht.keys():
        print key


if __name__ == "__main__":
    # Get3754()
    # Get3751()
    # Compare_3751_3754()
    # import sys
    # GetLines(sys.argv[1])
    Find3()
